<!DOCTYPE html>
<html lang="en">



<!-- https://zhuanlan.zhihu.com/p/34486016 -->

<!-- https://juejin.cn/post/6953145161895378951#heading-1 -->

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>测试</title>
    <style>
        div {
            width: 100px;
            height: 300px;
            border: 1px solid skyblue;
            margin: 12px;
            padding: 8px;
        }

        .div_two {
            position: relative;
            /* top: 12px;
            left: 12px; */
        }

        .main {
            height: 500px;
            margin: 0 auto;
            /* margin-top: 40px; */
            overflow-y: auto;
        }

        .hearder {
            position: sticky;
            position: -webkit-sticky;
            top: 0;
            border: 1px solid pink;
        }
    </style>
</head>

<body>
    <!-- <input type="checkbox" value="a" />
    <input type="radio" value="a" /> -->
    <!-- <main class="main"> -->
    <!-- <div>
        1
    </div>
    <header class="hearder">
        <button onclick="handle(this)">点击事件</button>
    </header>

    <div class="div_two">
        2
    </div>
    <div>
        3
    </div>
    <div>
        3
    </div>
    <div>
        3
    </div> -->
    <!-- </main> -->
    <script>


        const handleError = (err) => {
            // 有两个异常，请求时候的异常，后台处理的异常不处理，异常信息是有的。不管那种类型的错误。
            console.log(err, err.code, err.statusText, err.message, err.fileName)
            throw Error('请求出现异常')
        }

        const request = (path, params = {}) => {
            const headers = new Headers({
                'Content-type': 'application/json'
            })
            const body = JSON.stringify({
                data: params
            })

            return fetch(path, {
                method: 'POST',
                credentials: "include",
                body,
                headers
            }).catch(handleError).then((res) => {
                // 出其他转态码的问题。
                res.json()
            }).then(data => {
                if (data?.code === 200 & data.enmsg === 'ok') {
                    return data?.data
                }
                if (data?.code === 401) {
                    console.log('权限不足')
                }
                let msg = '请求出现异常'
                alert()
                return Promise.reject(data)
            })
        }

    </script>
    <script>
        // this 传递的是当前组件本身，值的话就是组件的值。
        // const handle = (e) => {
        //     // console.log(e)
        //     request('/admin/231311')
        // }
        const getdata = async () => {
            try {

                // throw new Error('hoa')
                console.log('12312')
                return Promise.reject({ code: 401, message: 'xxxx' })
            } catch (error) {
                // debugger
                console.log(error)
                return Promise.reject({ code: 401, message: error.message })
            }
        }
        getdata().catch((data) => {
            console.log(data)
        })
        /** replace 方法 */
        const str = 'aaaab'
        console.log(str.replace('a', 'c'))

        const date = new Date('2015-11-10 3:1:2')
        console.log(date.toLocaleDateString(), date.toLocaleTimeString())

    </script>

</body>

</html>